package com.example.bysj.Service;

import com.example.bysj.Dao.*;
import com.example.bysj.domain.Student;
import com.example.bysj.domain.Teacher;
import com.example.bysj.domain.authority.Resource;
import com.example.bysj.domain.authority.Role;
import com.example.bysj.domain.authority.RoleAssResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
//声明一个业务处理类
@Service
public class RoleAssResourceService {
    //自动注入
    @Autowired
    private RolePermissionDao rolePermissionDao;
    @Autowired
    private RoleDao roleDao;
    @Autowired
    private ResourceDao resourceDao;

    //事务，添加角色的同时添加权限
    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation. REQUIRED)
    public String addRoleAssResourceTran(RoleAssResource roleAssResource, Role role, Resource resource){
        rolePermissionDao.add(roleAssResource);
        roleDao.add(role);
        resourceDao.add(resource);
        return "添加成功！";
    }
}
